package com.github.binarywang.demo.wx.mp.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@ApiModel("返回实体")
public class Result<T> implements Serializable {

    //返回编码
    @ApiModelProperty("响应码 200成功")
    private Integer code;
    //返回信息
    @ApiModelProperty("提示")
    private String msg;
    //具体返回的数据
    @ApiModelProperty("数据")
    private T data;

    public static <T> Result<T> success(T data) {
        return new Result<>(200,"请求成功", data);
    }

    public static <T> Result<T> success(String msg) {
        return new Result<>(200, msg,null);
    }

    public static <T> Result<T> error() {
        return new Result<>(400, "请求失败了!",null);
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(400, msg,null);
    }
    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
